fix: Add missing dependencies to useEffect and React.memo calls (#5289) #5310
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
The merge of #5261 caused a regression where the first value of onChange is cached indefinitely because it is not used as a dependency of the effect that is supposed to maintain it. This fixes that bug, and similar bugs in the React.memo comparisons for MemoizedElement and MemoizedText where a cached
renderPlaceholder
is passed down to the leaf.Issue
Fixes: #5289
Example
See the recording in #5289 for an example of the bug. A similar one could be crafted with renderPlaceholder being cached if necessary, but it should be pretty clear from the code.
Context
There aren't really other ways to fix these issues in a localized manner. I did look into adding the eslint plugin that can help check hook dependencies but there are violations in the code that would require distracting workarounds or API changes so I opted to keep it concise.
Checks
yarn test
.yarn lint
. (Fix errors withyarn fix
.)yarn start
.)yarn changeset add
.)